//
//

	
var GameData = require("GameData");
cc.Class({
    extends: cc.Component,

    properties: {

        mIndexLabel: cc.Label,
        mImg:cc.Sprite,
        mNameLabel: cc.Label,
        mScoreLabel: cc.Label,
        mOpenId: {
            default: null,
            visible: false,
        },
        mDepth:{
            default: 0,
            visible: false,
        },

        mBack:[cc.SpriteFrame],
        mNameNode: cc.Node,
        mScoreNode: cc.Node,

    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {

    },

    // update (dt) {},

    init(index,imgURL,name,depth,score,openid){

        let bg = this.node.getComponent(cc.Sprite);
        bg.spriteFram = this.mBack[index %2];
        this.mIndexLabel.string = index;

        let image = wx.createImg();
        image.onLoad = ()=>{
            let texture = new cc.Texture2D();
            texture.initWithElement(image);
            texture.handleLoadedTexture();
            this.mImg.spriteFram = new cc.SpriteFrame(texture);
        }
        image.src = imgURL;
        if(openid == GameData.instance.openId){
	
            this.mNameNode.color = cc.color(255,215,0,255);
            this.mScoreNode.color = cc.color(255,215,0,255);
        }else{
            this.mNameNode.color = cc.color(255,255,255,255);
            this.mScoreNode.color = cc.color(255,255,255,255);
        }

        this.mNameLabel.string = name;
        this.mDepth = depth;
        this.mScoreLabel.string = score;
        this.mOpenId = openid;
    }

});
